package by.msokoloff.javaweb2015.services.impl;

import java.util.List;

import javax.inject.Inject;
import javax.persistence.metamodel.SingularAttribute;

import org.springframework.stereotype.Service;

import by.msokoloff.javaweb2015.dataaccess.ExtraDao;
import by.msokoloff.javaweb2015.datamodel.Extra;
import by.msokoloff.javaweb2015.services.ExtraService;

@Service
public class ExtraServiceImpl implements ExtraService {
	
	@Inject
	private ExtraDao dao;
	
	@Override
	public Extra get(Integer id) {
		return dao.getById(id);
	}
	
	@Override
	public List<Extra> getAll() {
		return dao.getAll();
	}

	@Override
	public void createOrUpdate(Extra extra) {
		if (extra.getId() == null) {
			dao.create(extra);
		} else {
			dao.update(extra);
		}		
	}

	@Override
	public void delete(Extra extra) {
		dao.delete(extra.getId());
	}

	@Override
	public void deleteAll() {
		dao.deleteAll();
	}

	@Override
	public long getCount() {
		return dao.getCount();
	}

	@Override
	public List<Extra> getAll(SingularAttribute<Extra, ?> sortParam, boolean ascending, int first, int count) {
		return dao.getAll(sortParam, ascending, first, count);
	}
	
}
